<div class="main-content">
    <div class="section__content section__content--p20">
        <div class="container-fluid">
            <div class="row m-b-30">
                <div class="col-lg-12">
                    <div class="overview-wrap">
                        <h2 class="title-1">FLASH编辑：<?php echo $flash['title']; ?>(<?php echo $flash['name']; ?>)</h2>
                        <button class="au-btn au-btn-icon au-btn--blue"  onclick="showedit()">
                            <i class="zmdi zmdi-plus"></i>添加图片轮换</button>
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-lg-12">
                    <div class="table-responsive table--no-card m-b-30">
                        <table class="table table-borderless table-striped table-earning">
                            <thead>
                            <tr>
                                <th>图片</th>
                                <th>标题</th>
                                <th>描述</th>
                                <th>排序</th>
                                <th>工具</th>
                            </tr>
                            </thead>
                            <tbody>
                            <?php
                            if (sizeof($flashimages) > 0) {
                                foreach ($flashimages as $f) {
                                    ?>
                                    <tr>
                                        <td><a href="<?php echo Yii::app()->theme->baseUrl ?>/<?php echo $f['imageurl']; ?>"
                                               class="review"><img width="200px" height="123" src="<?php echo $f['imageurl']; ?>"/></a>
                                        </td>
                                        <td><?php echo $f['title']; ?></td>
                                        <td><?php echo $f['imagedesc']; ?></td>
                                        <td><?php echo $f['seq']; ?></td>
                                        <td>

                                            <button type="button" class="btn btn-primary btn-sm"
                                                    onclick="showedit(<?php echo $f['flashimage_id']; ?>)">编辑</button>

                                            <button type="button" class="btn btn-danger btn-sm" onclick="del(<?php echo $f['flashimage_id']; ?>)">删除</button>

                                        </td>
                                    </tr>
                                    <?php
                                }
                            }
                            ?>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>

            <div class="row" id="flashitem_form" style="display: none;">
                <div class="col-lg-12">
                    <div class="card">
                        <div class="card-header">
                            <strong>图片轮换编辑</strong>
                        </div>
                        <div class="card-body">
                            <form class="form-horizontal" role="form" name="form" id="form" method="post"
                                  data-bv-feedbackicons-valid="glyphicon glyphicon-ok"
                                  data-bv-feedbackicons-invalid="glyphicon glyphicon-remove"
                                  data-bv-feedbackicons-validating="glyphicon glyphicon-refresh"
                                  action="index.php?r=admin/flash/edit">
                                <input type="hidden" name="flashimage_id"/>
                                <input type="hidden" name="flash_id" value="<?php echo $flash_id; ?>"/>
                                <input type="hidden" name="YII_CSRF_TOKEN"
                                       value="<?php echo Yii::app()->request->csrfToken; ?>"/>

                                <div class="form-group">
                                    <label class=" form-control-label">图片</label>
                                    <input type="text" class="form-control" name="imageurl" >
                                </div>

                                <div class="form-group">
                                    <label class=" form-control-label">标题</label>
                                    <input type="text" class="form-control" name="title"/>
                                </div>

                                <div class="form-group">
                                    <label class=" form-control-label">链接</label>
                                    <input type="text" class="form-control" name="link"/>
                                </div>

                                <div class="form-group">
                                    <label class=" form-control-label">描述</label>
                                    <textarea class="form-control" name="imagedesc"></textarea>

                                </div>

                                <div class="form-group">
                                    <label class=" form-control-label">排序</label>
                                    <input type="text" class="form-control"
                                           name="seq" />
                                </div>

                                <div class="form-group">
                                    <button  type="submit" name="submit" id="submit" class="btn btn-primary btn-lg btn-block">保存</button>
                                </div>

                            </form>
                        </div>
                    </div>
                </div>
            </div>

        </div>
    </div>
</div>

<script>
    var current = null;
    var flash_id = <?php echo $flash_id; ?>;
    $(function () {
        initPage();
    });
    function initPage() {
        $('#form').bootstrapValidator();
        $('#form').ajaxForm({
            dataType: 'json',
            beforeSubmit: function (formData, jqForm, options) {
                return $('#form').data('bootstrapValidator').isValid();
            },
            success: function (res) {
                if (message(res)) {
                    window.location.href = "index.php?r=admin/flash/showedit&flash_id="+flash_id;
                }
            }
        });
    }
    function showedit(fmid) {
        current = fmid;
        if (fmid != null) {
            $("#form").attr("action", "index.php?r=admin/flash/edit");
            //加载flash信息
            $.get('index.php?r=admin/flash/json&id='+fmid,null,function (res) {
                if(message(res)){
                    $("input[name=flashimage_id]").val(res.data.flashimage_id);
                    $("input[name=imageurl]").val(res.data.imageurl);
                    $("input[name=title]").val(res.data.title);
                    $("input[name=link]").val(res.data.link);
                    $("textarea[name=imagedesc]").val(res.data.imagedesc);
                    $("input[name=seq]").val(res.data.seq);

                    $("#flashitem_form").show();
                    $("#flashitem_list").hide();
                    $("#toolbr").hide();
                }
            },'json');
        } else {
            $("#form").attr("action", "index.php?r=admin/flash/add");
            $("#flashitem_form").show();
            $("#flashitem_list").hide();
            $("#toolbr").hide();
        }
    }
    function del(fmid) {
        $.get("index.php?r=admin/flash/del&flashimage_id=" + fmid,null,function (res) {
            if(message(res)){
                window.location.href = "index.php?r=admin/flash/showedit&flash_id="+flash_id;
            }
        },'json');
    }
</script>